package com.yunxi.service.dubboService.impl.sys;

import com.aiways.center.channel.api.IChannelPersonalApi;
import com.aiways.center.channel.api.dto.request.ChannelPersonalReqDto;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dtyunxi.rest.RestResponse;
import com.github.pagehelper.PageInfo;
import com.yunxi.baseDataToHub.pojo.iam.PmsUserVO;
import com.yunxi.baseDataToHub.service.iam.IamDubboService;
import com.yunxi.core.util.BeanTools;
import com.yunxi.core.util.DESUtil;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.DictConstant;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.dealer.pojo.AreaManagerVO;
import com.yunxi.dealer.pojo.PartnerVO;
import com.yunxi.dealer.service.AreaManagerDubboService;
import com.yunxi.dealer.service.PartnerDubboService;
import com.yunxi.hubToBaseData.pojo.RegionManagerReqVO;
import com.yunxi.hubToBaseData.pojo.RegionManagerVO;
import com.yunxi.hubToBaseData.service.App2BaseDataService;
import com.yunxi.model.sys.Staff;
import com.yunxi.service.localService.sys.StaffService;
import com.yunxi.sys.pojo.*;
import com.yunxi.sys.service.AreaDubboService;
import com.yunxi.sys.service.RoleUserDubboService;
import com.yunxi.sys.service.StaffDubboService;
import com.yunxi.sys.service.UserDubboService;
import com.yunxi.util.S2SEnums;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 员工信息 服务实现类
 * </p>
 *
 * @author
 * @since 2019-05-20
 */
public class StaffDubboServiceImpl implements StaffDubboService,App2BaseDataService {

   private static final Logger logger = LoggerFactory.getLogger(StaffDubboServiceImpl.class);

   @Autowired
   @Qualifier(value = "staffServiceImpl")
   StaffService staffService;

   @Autowired
   IamDubboService iamDubboServiceImpl;

   @Autowired
   RoleUserDubboService roleUserDubboServiceImpl;

   @Autowired
   UserDubboService userDubboServiceImpl;

   @Autowired
   AreaManagerDubboService areaManagerDubboServiceImpl;

   @Autowired
   IChannelPersonalApi channelPersonalApi;

   @Autowired
   AreaDubboService areaDubboServiceImpl;

   @Autowired
   PartnerDubboService partnerDubboServiceImpl;

   @Value("${iam.switch}")
   private String is2IAM;

   @Value("${center.switch}")
   private String is2Center;

   @Override
   public StaffVO getById(String id) throws InvocationTargetException, IllegalAccessException {
      Staff staff = staffService.getById(id);
      StaffVO staffVO = new StaffVO();
      BeanUtils.copyProperties(staff, staffVO);
      return staffVO;
   }

   @Override
   @Transactional
   public ApiResult saveOrUpdate(StaffVO staffVO,LoginInfo loginInfo) throws Exception {
      if (StringUtils.isNotEmpty(loginInfo.getPartnerCode()) ){
         StaffVO staff = staffService.getByUserCode(loginInfo.getUserCode());
         staffVO.setTenantId(staff.getTenantId());
      }
      boolean isFirst = false;
      if (StringUtils.isEmpty(staffVO.getStaffId())) {
         staffVO.setStatus(1);
         isFirst = true;
      }
      UserVO user = staffVO.getUserVO();
      if (StringUtils.isEmpty(staffVO.getOrgId())) {
         staffVO.setOrgId(staffVO.getPartnerCode());
      }

      //创建或修改 用户信息
      if (isFirst) {
         //需要补充
         if (StringUtils.isNotEmpty(staffVO.getPartnerCode())){
            staffVO.setAccountNo("PMS_"+staffVO.getAccountNo()+"A");
         }
         StaffVO staffVO1 = staffService.getByUserCode(staffVO.getAccountNo());
         if (staffVO1!=null && StringUtils.isNotEmpty(staffVO1.getStaffId())) throw new Exception("该账号已存在"+staffVO.getAccountNo());
         UserVO userVO = userDubboServiceImpl.getByUserCode(staffVO.getAccountNo());
         if (userVO!=null && StringUtils.isNotEmpty(userVO.getUserId())) throw new Exception("该用户已存在"+staffVO.getAccountNo());
         user.setTenantId(staffVO.getTenantId());
         user.setUserCode(staffVO.getAccountNo());

         user.setPassword(DESUtil.encrypt("aiways"));
         staffVO.setPassword(DESUtil.encrypt("aiways"));
         //user.setUserNo();
         user.setRealName(staffVO.getStaffName());
         user.setUserName(staffVO.getStaffName());
         user = userDubboServiceImpl.save(user);

      }else {
         HashMap<String, String> map = new HashMap<>();
         map.put("userCode", staffVO.getAccountNo());
         UserVO userVO = userDubboServiceImpl.findUserByUserCode(map);
         if("1".equals(staffVO.getOp())) {
            if (staffVO.getStatus().equals(0)) {//禁用
               userVO.setStatus(0);//0禁用 1启用
               userVO.setIsOpen(1);//账户状态（是否游客状态）1是
            }
            if (staffVO.getStatus().equals(1)) {//启用
               userVO.setStatus(1);//0禁用 1启用
               userVO.setIsOpen(0);//账户状态（是否游客状态）1是
            }
         }
         userVO.setUserName(staffVO.getStaffName());
         userVO.setRealName(staffVO.getStaffName());
         userDubboServiceImpl.saveOrUpdate(userVO);
      }

      if (staffVO.getRoleList() != null) {
         roleUserDubboServiceImpl.delByUserId(user.getUserId());
         for (int i = 0; i < staffVO.getRoleList().size(); i++) {
            RoleVO roleVO = staffVO.getRoleList().get(i);
            if (roleVO.getIsSelect()!=null&&roleVO.getIsSelect()==1) {
               RoleUserVO ru = new RoleUserVO();
               ru.setRoleId(roleVO.getRoleId());
               ru.setUserId(user.getUserId());
               roleUserDubboServiceImpl.save(ru);
            }
         }
      }
      Staff staff = new Staff();
      BeanUtils.copyProperties(staffVO, staff);
      staffService.saveOrUpdate(staff);

      //如果角色列表里不存在销售顾问角色,则用 用户账号去查询pms_sat_target是否存在记录,存在则删除
      checkSalesTarget(staffVO);

      if (isFirst) {
         //将人员信息传入 IAM
         if("true".equals(is2IAM)){
            if (StringUtils.isNotEmpty(staffVO.getPartnerCode())) {
               ApiResult apiResult = pms2IAM(staffVO, S2SEnums.OperatorType.insert.getKey());
               if (apiResult != null) return apiResult;
            }
         }
         //将渠道人员信息传入中台
         if("true".equals(is2Center)) {
            if (StringUtils.isNotEmpty(staffVO.getPartnerCode())){
               ChannelPersonalReqDto channelPersonalReqDto = setChannelPersonalReqDto(staffVO);
               if(pms2CenterChannelPersonalAdd(channelPersonalReqDto)) return ResponseUtil.fail(-1,"----新增渠道人员传入中台错误----");;
            }
         }
      } else {
         //将人员信息传入 IAM
         if("true".equals(is2IAM)){
            if (StringUtils.isNotEmpty(staffVO.getPartnerCode())) {
               ApiResult apiResult = pms2IAM(staffVO, S2SEnums.OperatorType.update.getKey());
               if (apiResult != null) return apiResult;
            }
         }
         //将渠道人员信息传入中台
         if("true".equals(is2Center)) {
            if (StringUtils.isNotEmpty(staffVO.getPartnerCode())) {
               ChannelPersonalReqDto channelPersonalReqDto = setChannelPersonalReqDto(staffVO);
               if (pms2CenterChannelPersonalUpdate(channelPersonalReqDto)) throw new Exception( "----修改渠道人员传入中台错误----");
            }
         }
      }
      return ResponseUtil.ok();
   }

   /**
    * 如果角色列表里不存在销售顾问角色,则用
    * 用户账号去查询pms_sat_target是否存在记录,存在则删除
    * @param staffVO
    */
   private void checkSalesTarget(StaffVO staffVO) {
      if (staffVO.getRoleList() != null) {
         List<RoleVO> roleList = staffVO.getRoleList();
         Boolean isExist = false;
         for(RoleVO vo : roleList){
            String roleCode = vo.getRoleCode();
            if(StringUtils.isNotEmpty(roleCode) && roleCode.equals(DictConstant.USER_ROLE_SALES)){
               isExist = true;
               break;
            }
         }
         if(!isExist){
            staffService.removeTargetByAccountNo(staffVO.getAccountNo());
         }
      }
   }

   @Override
   public ApiResult saveCityManager(List<StaffVO> staffVOList, LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {
      if (staffVOList==null || staffVOList.size()<=0 ) return ResponseUtil.fail();
      for (StaffVO staffVO : staffVOList) {
         //配置小区经理
         if (staffVO.getAreaCode()!= null && staffVO.getAreaCode().size()>0 ){
            AreaManagerVO areaManagerVO = new AreaManagerVO();
            areaManagerVO.setUserCode(staffVO.getAccountNo());
            areaManagerVO.setPCode(staffVO.getPCode());
            areaManagerDubboServiceImpl.delByUserCode(staffVO.getAccountNo());
            for (String areaCode : staffVO.getAreaCode()) {
               areaManagerVO.setAreaCode(areaCode);
               areaManagerDubboServiceImpl.saveOrUpdate(areaManagerVO);
            }
         }
      }
      return ResponseUtil.ok();
   }

   @Override
   public PageInfo listCityManagerByAccountNo(String accountNo, Integer pageNum, Integer pageSize) {
      return staffService.listCityManagerByAccountNo(accountNo,pageNum,pageSize);
   }

   @Override
   public List<StaffVO> listRegionManagerByPartnerCode(String partnerCode, LoginInfo loginInfo) {

      String provinceCode = null;
      PartnerVO vo = new PartnerVO();
      vo.setPartnerCode(partnerCode);
      List<PartnerVO> list = partnerDubboServiceImpl.listByVo(vo);
      if (list!=null && list.size()>0){
         provinceCode = list.get(0).getProvince();
      }

      AreaVO areaVO = areaDubboServiceImpl.getByProvinceCode(provinceCode);
      List<StaffVO> staffVOList = staffService.listRegionManagerByAreaCode(areaVO.getCode());
      return staffVOList;
   }

   @Override
   public List<StaffVO> listCityManagerByPartnerCode(String partnerCode, LoginInfo loginInfo) {
      String cityCode = null;
      PartnerVO vo = new PartnerVO();
      vo.setPartnerCode(partnerCode);
      List<PartnerVO> list = partnerDubboServiceImpl.listByVo(vo);
      if (list!=null && list.size()>0){
         cityCode = list.get(0).getCity();
      }
      List<StaffVO> cityManagerList = staffService.listCityManagerByCityCode(cityCode);
      return cityManagerList;
   }

   @Override
   public List<StaffVO> listCityManagerByPartnerCode(String cityCode) {
      return staffService.listCityManagerByCityCode(cityCode);
   }

   /**
    * 导入更新培训状态
    * @param staffVOList
    * @param loginInfo
    * @return
    */
   @Override
   public ApiResult updateBatchTraining(List<StaffVO> staffVOList, LoginInfo loginInfo) throws IllegalAccessException {
      if (staffVOList==null || staffVOList.size()<=0) return ResponseUtil.fail(-1,"请上传正确模板");
      if (staffVOList!=null && staffVOList.size()>0){
         for (StaffVO staffVO : staffVOList) {
            if (BeanTools.isAllFieldNull(staffVO)) return ResponseUtil.fail(-1,"请上传正确格式");
            if (StringUtils.isEmpty(staffVO.getAccountNo())) return ResponseUtil.fail(-1,"请输入员工账号");
            if ("未参加".equals(staffVO.getIsTrainingName())){
               staffVO.setIsTraining("0");
            }else {
               staffVO.setIsTraining("1");
            }
            staffVO.setUpdateBy(loginInfo.getUserCode());

            Staff staff = new Staff();
            BeanUtils.copyProperties(staffVO,staff);
            QueryWrapper<Staff> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("ACCOUNT_NO",staff.getAccountNo());

            List<Staff> list = staffService.list(queryWrapper);
            if (list==null || list.size()<=0) return ResponseUtil.fail(-1,"输入账号不正确"+staffVO.getAccountNo());
            staffService.update(staff,queryWrapper);
         }
      }
      return ResponseUtil.ok();
   }

   @Override
   @Transactional
   public ApiResult saveOrUpdate(List<StaffVO> staffVOList, LoginInfo loginInfo) throws Exception {
      if (staffVOList==null || staffVOList.size()<=0 ) return ResponseUtil.fail();
      for (StaffVO staffVO : staffVOList) {
         //配置大区经理
         if (staffVO.getAreaCode()!= null && staffVO.getAreaCode().size()>0 ){
            AreaManagerVO areaManagerVO = new AreaManagerVO();
            areaManagerVO.setUserCode(staffVO.getAccountNo());
            areaManagerVO.setPCode("0");
            for (String areaCode : staffVO.getAreaCode()) {
               areaManagerVO.setAreaCode(areaCode);
               areaManagerDubboServiceImpl.saveOrUpdate(areaManagerVO);
            }
         }
      }
      return ResponseUtil.ok();
   }

   @Override
   public void save(StaffVO staffVO) throws Exception {
      Staff staff = new Staff();
      BeanUtils.copyProperties(staffVO,staff);
      staffService.save(staff);
   }

   private ApiResult pms2IAM(StaffVO staffVO, String op) throws Exception {
      PmsUserVO pmsUserVO = new PmsUserVO();
      ArrayList<PmsUserVO> list = new ArrayList<>();
      pmsUserVO.setAccount(staffVO.getAccountNo());//账号
      pmsUserVO.setPassword(staffVO.getPassword());//密码
      pmsUserVO.setPartnerCode(staffVO.getPartnerCode());//渠道CODE
      pmsUserVO.setUserName(staffVO.getStaffName());//姓名
      pmsUserVO.setOperator(op);//操作符
      pmsUserVO.setLevel("N");
      if (staffVO.getRoleList()!=null && staffVO.getRoleList().size()>0){
         for (RoleVO roleVO : staffVO.getRoleList()) {
            if (roleVO.getIsSelect()!=null
                    &&roleVO.getIsSelect()==1
                    &&"rolePartnerAdmin".equals(roleVO.getRoleCode()) ){
               pmsUserVO.setLevel("Y");//是否管理员:Y/N
               break;
            }
         }
      }else {
         pmsUserVO.setLevel("N");//是否管理员:Y/N
      }

      pmsUserVO.setEmail(staffVO.getEmail());//邮箱
      pmsUserVO.setPhone(staffVO.getMobilePhone());//g管理员默认位渠道中的电话
      pmsUserVO.setOrganizationCode(staffVO.getOrgCode());//部门编码
      if (staffVO.getStatus()!=null){
         pmsUserVO.setIsEnable(String.valueOf(staffVO.getStatus()));//是否禁用
      }
      pmsUserVO.setPositionCode(staffVO.getPositionCode());//职位编码
      pmsUserVO.setStatus("1");//服务商状态
      list.add(pmsUserVO);
      ApiResult apiResult = iamDubboServiceImpl.sendIamUserVO(list);
      if (apiResult.getCode().equals(-1)) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error("  ------- pms2IAM 执行失败 ___人员信息  ---------  ");
         return ResponseUtil.fail(-1,"pms2IAM 执行失败"+apiResult.getMsg());
      }
      return null;
   }

   @Override
   public void removeById(String id) throws Exception {
      Staff staff = staffService.getById(id);

      //将人员信息传入 IAM
      StaffVO staffVO = new StaffVO();
      BeanUtils.copyProperties(staff, staffVO);
      pms2IAM(staffVO, S2SEnums.OperatorType.delete.getKey());

      staffService.removeById(id);
   }

   @Override
   public PageInfo<StaffVO> findPageByVO(StaffVO staffVO, Integer pageNum, Integer pageSize,LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {
      if (StringUtils.isNotEmpty(loginInfo.getPartnerCode()) ){
         StaffVO staff = staffService.getByUserCode(loginInfo.getUserCode());
         staffVO.setTenantId(staff.getTenantId());
         staffVO.setPartnerCode2(staff.getPartnerCode());
      }
      PageInfo<StaffVO> pageInfo = staffService.pageByVo(staffVO, pageNum, pageSize);

      return pageInfo;
   }

   @Override
   public void removeByListVo(List<StaffVO> staffVOList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
      staffService.removeByListVo(staffVOList);
   }

   @Override
   public List listByVO(StaffVO staffVO,LoginInfo loginInfo) {
      if (StringUtils.isNotEmpty(loginInfo.getPartnerCode()) ){
         StaffVO staff = staffService.getByUserCode(loginInfo.getUserCode());
         staffVO.setTenantId(staff.getTenantId());
         staffVO.setPartnerCode(staff.getPartnerCode());
      }
      return staffService.listByVo(staffVO);
   }

   @Override
   public StaffVO getByUser(UserVO user) {
      return staffService.getByUserCode(user.getUserCode());
   }

   @Override
   public StaffVO getCasById(String staffId) {
      return staffService.getCasById(staffId);
   }

   /**
    * 查询店端角色
    * @param loginInfo
    * @return
    */
   @Override
   public List<RoleVO> listRole(LoginInfo loginInfo) {
      StaffVO staff = staffService.getByUserCode(loginInfo.getUserCode());
      String tenantId = null;
      if (staff!=null){
         tenantId = staff.getTenantId();
      }
      return staffService.listRole(tenantId);
   }

   @Override
   public void batchCreateUser(String flag) throws InvocationTargetException, IllegalAccessException {
      staffService.batchCreateUser(flag);
   }

   @Override
   public List<StaffVO> listByPartnerCode(String partnerCode) throws InvocationTargetException, IllegalAccessException {

      return staffService.listByPartnerCode(partnerCode);
   }

   @Override
   public List<StaffVO> listManagerByPartnerCode(String partnerCode) throws InvocationTargetException, IllegalAccessException {
      return staffService.listManagerByPartnerCode(partnerCode);
   }

   @Override
   public PageInfo listRegionManager(String areaCode,Integer pageNum, Integer pageSize) {
      return staffService.listRegionManager(areaCode,pageNum, pageSize);
   }

   @Override
   public PageInfo listAllRegionManager(Integer pageNum, Integer pageSize) {
      return staffService.listAllRegionManager(pageNum,pageSize);
   }

   @Override
   public PageInfo listRegionManagerNotExits(String areaCode, Integer pageNum, Integer pageSize) {
      return staffService.listRegionManagerNotExits(areaCode,pageNum, pageSize);
   }

   @Override
   public ApiResult listStaffByRoleCode(String roleCode, LoginInfo loginInfo) {
      return staffService.listStaffByRoleCode(roleCode,loginInfo);
   }

   @Override
   public String getBigRegionCode(String userCode) {
      AreaManagerVO vo = new AreaManagerVO();
      vo.setUserCode(userCode);
      vo.setPCode("0");
      List<AreaManagerVO> list = areaManagerDubboServiceImpl.listByVo(vo);
      if (list!=null && list.size()>0){
         return list.get(0).getAreaCode();
      }else {
         return null;
      }
   }

   @Override
   public List<StaffVO> getRegionManagerByUserCode(String fellowId) {
      return staffService.getRegionManagerByUserCode(fellowId);
   }

   @Override
   public ApiResult a(String provinceCode) {
      RegionManagerReqVO regionManagerReqVO = new RegionManagerReqVO();
      regionManagerReqVO.setCityId(provinceCode);
      return ResponseUtil.ok(listRegionManager(regionManagerReqVO)) ;
   }

   @Override
   public PageInfo listAllCityManager(Integer pageNum, Integer pageSize) {
      return staffService.listAllCityManager(pageNum,pageSize);
   }

   @Override
   public PageInfo listCityManagerNotExits(Integer pageNum, Integer pageSize) {
      return staffService.listCityManagerNotExits(pageNum,pageSize);
   }


   /**
    * 通过组织id获取该组织下人员
    *
    * @param orgId
    * @return
    */
   @Override
   public List<StaffListVO> getStaffListById(String orgId) {
      List<StaffListVO> list = staffService.getStaffListById(orgId);
      return list;
   }


   private ChannelPersonalReqDto setChannelPersonalReqDto( StaffVO staffVO) {
      ChannelPersonalReqDto channelPersonalReqDto = new ChannelPersonalReqDto();
      channelPersonalReqDto.setChannelCode(staffVO.getPartnerCode());//渠道商代码
      channelPersonalReqDto.setAccount(staffVO.getAccountNo());//登录账号
      channelPersonalReqDto.setPassword(staffVO.getPassword());//密码
      channelPersonalReqDto.setRealName(staffVO.getStaffName());//姓名
      channelPersonalReqDto.setNickName("");//昵称
      channelPersonalReqDto.setPhone(staffVO.getMobilePhone());//联系电话
      channelPersonalReqDto.setEmail("");//邮箱
      if (staffVO.getRoleList() != null) {
         for (int i = 0; i < staffVO.getRoleList().size(); i++) {
            RoleVO roleVO = staffVO.getRoleList().get(i);
            if (roleVO.getIsSelect()!=null&&roleVO.getIsSelect()==1) {
               if ("rolePartnerAdmin".equals(roleVO.getRoleCode())){
                  channelPersonalReqDto.setLevel("Y");//是否管理员:Y/N
               }else {
                  channelPersonalReqDto.setLevel("N");//是否管理员:Y/N
               }
            }
         }
      }else {
         channelPersonalReqDto.setLevel("N");//是否管理员:Y/N
      }
      channelPersonalReqDto.setOrganizationCode("");//部门编码
      channelPersonalReqDto.setOrganizationName("");//部门名称
      channelPersonalReqDto.setPositionCode(staffVO.getPositionId());//职位编码
      channelPersonalReqDto.setPositionName("");//职位名称
      channelPersonalReqDto.setStatus(staffVO.getStatus());//状态1启用0禁用
      return channelPersonalReqDto;
   }


   private boolean pms2CenterChannelPersonalAdd(ChannelPersonalReqDto channelPersonalReqDto) {
      RestResponse<Long> longRestResponse = null;
      try {
         longRestResponse = channelPersonalApi.addChannelPersonal(channelPersonalReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错_pms2CenterChannelPersonalAdd ___< 新增渠道人员信息  >----"+e.getMessage());
         e.printStackTrace();
         return true;
      }
      if (!longRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败_pms2CenterChannelPersonalAdd ___< 新增渠道人员信息  >-------"+longRestResponse.getResultMsg());
         return true;
      }
      return false;
   }

   private boolean pms2CenterChannelPersonalUpdate(ChannelPersonalReqDto channelPersonalReqDto) {
      RestResponse<Void> voidRestResponse = null;
      try {
         voidRestResponse = channelPersonalApi.updateChannelPersonal(channelPersonalReqDto.getAccount(),channelPersonalReqDto);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台调用出错_pms2CenterChannelPersonalUpdate ___< 修改渠道人员信息  >--------"+e.getMessage());
         e.printStackTrace();
         return true;
      }
      if (!voidRestResponse.getResultCode().equals("0")) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error(" ------- 中台执行失败_pms2CenterChannelPersonalUpdate ___< 修改渠道人员信息  >--------"+voidRestResponse.getResultMsg());
         return true;
      }
      return false;
   }

   /**
    *
    * app 根据省市区 查询小区经理
    * @param regionManagerReqVO
    * @return
    */
   @Override
   public List<RegionManagerVO> listRegionManager(RegionManagerReqVO regionManagerReqVO) {
      List<StaffVO> staffVOList = staffService.listCityManagerByCityCode(regionManagerReqVO.getCityId());

      List<RegionManagerVO> regionManagerVOList = new ArrayList<>();
      if (staffVOList!=null && staffVOList.size()>0){
         for (StaffVO staffVO : staffVOList) {
            RegionManagerVO regionManagerVO = new RegionManagerVO();
            regionManagerVO.setUserId(staffVO.getAccountNo());
            regionManagerVO.setName(staffVO.getStaffName());
            regionManagerVO.setPhone(staffVO.getMobilePhone());
            if (staffVO.getGender()!=null){
               regionManagerVO.setSex(String.valueOf(staffVO.getGender()));
            }
            regionManagerVO.setPosition(staffVO.getPositionCode());
            regionManagerVO.setPhoto(staffVO.getPictureUrl());
            regionManagerVO.setStatus(staffVO.getStaffStatus());
            regionManagerVOList.add(regionManagerVO);
         }
      }
      return regionManagerVOList;
   }
}
